<!DOCTYPE html>
<html lang="en">
    <head>
        <title>promise的race方法</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="css/style.css" rel="stylesheet">
    </head>
    <body>
    
    </body>
    <script>
        //race() 将多个promise实例包装成一个新的promise对象
        //如果多个实例中状态都为fulfilled，那么优先执行第一个为fulfilled实例
        //如果实例中存在rejected状态，不会影响整体执行，只要有fulfilled存在，就一定会走.then
    let promise1 = new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(1000)
        }, 1000)
    })

    let promise2 = new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve('hello')
        }, 1000)
    })

    let promise3 = new Promise((resolve, reject) => {
        setTimeout(() => {
            reject('promise3失败了')
        }, 1000)
    })

    let promise4 = Promise.race([promise1, promise2, promise3])
       .then((res) => {
            console.log(res);
        })
       .catch((err) => {
            console.log(err)
        })
</script>
</html>